package com.travel.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
import com.travel.system.entity.Cuisine;
import com.travel.system.mapper.CuisineMapper;
import com.travel.system.service.CuisineService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;
import java.util.stream.Collectors;

@Service
@Slf4j
public class CuisineServiceImpl extends ServiceImpl<CuisineMapper, Cuisine> implements CuisineService {

    @Override
    public List<Cuisine> getFive() {
        List<Cuisine> list = this.list(new LambdaQueryWrapper<Cuisine>().orderByDesc(Cuisine::getId));
        List<Cuisine> res = Lists.newArrayList();
        if (!CollectionUtils.isEmpty(list)) {
            res = list.stream().limit(5).collect(Collectors.toList());
        }
        return res;
    }
}
